package com.kang.until;

import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.kang.pojo.GeneralStorage;
import com.kang.pojo.GgeneralStoragePoJo;
import com.kang.pojo.InventoryLoss;
import com.kang.pojo.InventoryLoss_itemInformation;
import com.kang.pojo.Picking;
import com.kang.pojo.PickingReturn;
import com.kang.pojo.PurchaseOrderItem;
import com.kang.pojo.PurchaseRequest;
import com.kang.pojo.ReturnOrder;
import com.kang.pojo.ReturnRequestItem;
import com.kang.pojo.WarehouseOrder;
import com.kang.pojo.WarehouseOrder_iteminformation;
import com.kang.pojo.WarehousePoJo;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
import com.vonechina.entity.page.ReturnAgentPage;
import com.vonechina.entity.page.WareHouseOrderPage;

/**
 * 入库管理、出库管理PDF下载
 * @author zs
 *
 */
public class StoragePDF {

	/**
	 * 字体
	 */
	public static BaseFont bf = null;
	private static com.lowagie.text.Font fontChinese_14;
	private static BaseFont bfChinese;
	private static com.lowagie.text.Font fontChinese_16;
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	/**
	 * 初始化字体
	 */
	static {
		try {
			bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建表格统一单元格样式
	 * 
	 * @param str
	 * @return
	 */
	public static Cell createTableCell(String str, Font font) {
		Cell cell = null;
		try {
			cell = new Cell(new Phrase(str, font));
			cell.setBorderColor(new Color(0, 0, 0));
			// 单元格水平对齐方式
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			// 单元格垂直对齐方式
			cell.setVerticalAlignment(Element.ALIGN_CENTER);
		} catch (BadElementException e) {
			e.printStackTrace();
		}
		return cell;
	}

	/**
	 * 创建表格并生成表头
	 * 
	 * @param title
	 * @param titleFont
	 * @param tableHeader
	 * @param headerFont
	 * @return
	 * @throws Exception
	 */
	public static Table createTable(String title, Font titleFont, String[] tableHeader, Font headerFont)
			throws Exception {
		Table table = new Table(tableHeader.length);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		// 表头说明
		Cell cell = createTableCell(title, titleFont);
		cell.setHeader(true);
		cell.setColspan(tableHeader.length);
		table.addCell(cell);
		// 表头
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createTableCell(tableHeader[i], headerFont);
			table.addCell(cell);
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		return table;
	}

	/**
	 * 设置表格数据
	 * 
	 * @param table
	 * @param columns
	 * @param values
	 * @param baseFont
	 * @throws Exception
	 */
	public static void setTableValue(Table table, String[] columns, List<?> values, Font baseFont) throws Exception {
		// 表格
		int length = table.getColumns();
		//System.out.println("==values==="+ values.size());
		//System.out.println("==columns==="+ columns.length);
		if (values != null) {
			for (int i = 0; i < values.size(); i++) {
				Object obj = values.get(i);
				//System.out.println("==obj==="+ obj.getClass());
				for (int j = 0; j < length; j++) {
					if (columns.length <= j) {
						table.addCell(createTableCell("", baseFont));
						continue;
					}
					String field = columns[j];
					String value = "";
					if (obj instanceof Map) {
						value = ((Map<?, ?>) obj).get(field).toString();
					} else {
						String methodName = "get" + field.substring(0, 1).toUpperCase() + field.substring(1);
						Method getterMethod = obj.getClass().getMethod(methodName);
						Object valueObj = getterMethod.invoke(obj);
						if (valueObj != null)
							value = valueObj.toString();
					}
					table.addCell(createTableCell(value, baseFont));
				}
			}
		}
	}
	
	/**
	 * 设置单元格格式
	 * @param cell 单元格
	 * @return
	 */
	public static Cell setInfoCellStyle(Cell cell) {
		cell.setBorderColor(new Color(0, 0, 0));
		// 单元格水平对齐方式
		cell.setHorizontalAlignment(Element.ALIGN_LEFT);
		// 单元格垂直对齐方式
		cell.setVerticalAlignment(Element.ALIGN_CENTER);
		return cell;
	}
	/**
	 * 创建表格统一单元格样式
	 * @param str
	 * @return
	 */
	public static Cell createCell(String str,com.lowagie.text.Font font){
		Cell cell = null;
		try {
			cell = new Cell(new Phrase(str,font));
			cell.setBorderColor(new Color(0, 0, 0));
			 //单元格水平对齐方式
	        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        //单元格垂直对齐方式
	        cell.setVerticalAlignment(Element.ALIGN_CENTER);
		} catch (BadElementException e) {
			e.printStackTrace();
		}
		return cell;
	}
	
//==============================================采购入库==================================================================	

	/**
	 * 生成采购入库PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildWarehouseOrderTable(List<WarehousePoJo> listWpj) throws BadElementException {
		
		Table table = new Table(6);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("采购入库",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(6);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{"入库编号", "仓库名称", "物料类型", "入库数量", "创建时间", "创建人"};
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		//System.out.println("=======listWpj======"+listWpj.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(listWpj!=null){
			int listSize=listWpj.size();
			for (int i = 0; i < listSize; i++) {
				Cell cell1 = createCell(listWpj.get(i).getWarehousenumber(),fontChinese_14);
				Cell cell2 = createCell(listWpj.get(i).getWarehousename(),fontChinese_14);
				Cell cell3 = createCell((Integer.parseInt(listWpj.get(i).getMaterialmaterial())==2?"IMPA物料":"普通物料").toString(),fontChinese_14);
				Cell cell4 = createCell(listWpj.get(i).getNumber().toString(),fontChinese_14);
				Cell cell5 = createCell(sdf.format(listWpj.get(i).getCreateTime()).toString(),fontChinese_14);
				Cell cell6 = createCell(listWpj.get(i).getLoginName(),fontChinese_14);
				
				table.addCell(cell1);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell6);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成采购入库PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File WarehouseOrderPDF(WarehouseOrder wod,List<WarehousePoJo> listWpj){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"采购入库_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("采购入库", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildWarehouseOrderTable(listWpj));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}

//===================================================普通入库=======================================================================
	
	/**
	 * 生成普通入库PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildNormalStorageTable(List<GgeneralStoragePoJo> listGspj) throws BadElementException {
		
		Table table = new Table(6);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("普通入库",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(6);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{"入库编号", "仓库名称", "物料类型", "入库数量", "提交时间", "创建人"};
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		System.out.println("=======listWpj======"+listGspj.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(listGspj!=null){
			int listSize=listGspj.size();
			for (int i = 0; i < listSize; i++) {
				Cell cell1 = createCell(listGspj.get(i).getWarehousenumber(),fontChinese_14);
				Cell cell2 = createCell(listGspj.get(i).getWarehousename(),fontChinese_14);
				Cell cell3 = createCell(listGspj.get(i).getMaterialmaterial(),fontChinese_14);
				Cell cell4 = createCell(listGspj.get(i).getStoragequantity().toString(),fontChinese_14);
				Cell cell5 = createCell(sdf.format(listGspj.get(i).getLastmodifiedtime()).toString(),fontChinese_14);
				Cell cell6 = createCell(listGspj.get(i).getLoginName(),fontChinese_14);
				
				table.addCell(cell1);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell6);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成普通入库PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File NormalStoragePDF(GeneralStorage gs, List<GgeneralStoragePoJo> listGspj){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"普通入库_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("普通入库", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildNormalStorageTable(listGspj));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}
	
	
//============================================领料出库====================================================================
	
	/**
	 * 生成领料出库PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildPickingTable(List<Picking> listpk) throws BadElementException {
		
		Table table = new Table(6);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("领料出库",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(6);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{"入库编号", "仓库名称", "部门", "领料人", "出库数量", "处理时间" };
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		System.out.println("=======listpk======"+listpk.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(listpk!=null){
			int listSize=listpk.size();
			for (int i = 0; i < listSize; i++) {
				Cell cell1 = createCell(listpk.get(i).getPickingNumber(),fontChinese_14);
				Cell cell2 = createCell(listpk.get(i).getWarehouseName(),fontChinese_14);
				Cell cell3 = createCell(listpk.get(i).getOrganizationName(),fontChinese_14);
				Cell cell4 = createCell(listpk.get(i).getCreatePersonName(),fontChinese_14);
				Cell cell5 = createCell(listpk.get(i).getNumber().toString(),fontChinese_14);
				Cell cell6 = createCell(sdf.format(listpk.get(i).getLastProcessingTime()).toString(),fontChinese_14);
				
				table.addCell(cell1);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell6);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成领料出库PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File PickingPDF(List<Picking> listpk){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"领料出库_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("领料出库", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildPickingTable(listpk));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}
	
//======================================领料归还==========================================================================
	
	/**
	 * 生成领料归还PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildPickingReturnTable(List<PickingReturn> listpr) throws BadElementException {
		
		Table table = new Table(6);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("领料归还",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(6);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{"入库编号", "仓库名称", "部门", "创建时间", "处理时间", "状态" };
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		System.out.println("=======listpk======"+listpr.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(listpr!=null){
			int listSize=listpr.size();
			
			for (int i = 0; i < listSize; i++) {
				//String str = (listpr.get(i).getStatus()==1)?"已提交":"未提交";
				Cell cell1 = createCell(listpr.get(i).getPickingreturnNumber(),fontChinese_14);
				Cell cell2 = createCell(listpr.get(i).getWarehouseName(),fontChinese_14);
				Cell cell3 = createCell(listpr.get(i).getCreatePerson(),fontChinese_14);
				Cell cell4 = createCell(sdf.format(listpr.get(i).getCreateTime()).toString(),fontChinese_14);
				Cell cell5 = createCell(sdf.format(listpr.get(i).getFinalProcessingTime()).toString(),fontChinese_14);
				Cell cell6 = createCell(((listpr.get(i).getStatus()==1)?"已提交":"未提交").toString(),fontChinese_14);
				table.addCell(cell1);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell6);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成领料归还PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File PickingReturnPDF(List<PickingReturn> listpr){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"领料归还_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("领料归还", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildPickingReturnTable(listpr));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}
	
//====================================待退货物资=================================================================
	
	/**
	 * 生成待退货物资PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildReturnAgentTable(List<ReturnRequestItem> rriList) throws BadElementException {
		
		Table table = new Table(8);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("待退货物资",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(8);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{ "批次号", "申请单号", "名称", "数量", "仓库", "邮轮", "物料", "提交时间" };
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		System.out.println("=======listpk======"+rriList.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(rriList!=null){
			int listSize=rriList.size();
			
			for (int i = 0; i < listSize; i++) {
				
				//String str = (listpr.get(i).getStatus()==1)?"已提交":"未提交";
				Cell cell1 = createCell(rriList.get(i).getBatchNumber(),fontChinese_14);
				Cell cell2 = createCell(rriList.get(i).getApplicationNo(),fontChinese_14);
				Cell cell3 = createCell(rriList.get(i).getChineseName(),fontChinese_14);
				Cell cell6 = createCell(rriList.get(i).getNumber().toString(),fontChinese_14);
				Cell cell4 = createCell(rriList.get(i).getWarehouseName(),fontChinese_14);
				Cell cell5 = createCell(rriList.get(i).getCruiseName(),fontChinese_14);
				Cell cell7 = createCell(rriList.get(i).getMaterialMaterial().toString(),fontChinese_14);
				Cell cell8 = createCell(sdf.format(rriList.get(i).getCommitTime()).toString(),fontChinese_14);
				table.addCell(cell1);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell6);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell7);
				table.addCell(cell8);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成待退货物资PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File ReturnAgentPDF(List<ReturnRequestItem> rriList){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"待退货物资_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("待退货物资", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildReturnAgentTable(rriList));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}
	
//=================================退货出库=====================================================================	

	/**
	 * 生成退货出库PDF文件
	 * @param request
	 * @param items
	 * @return
	 */
	public static Table buildReturnOrderTable(List<ReturnOrder> roList) throws BadElementException {
		
		Table table = new Table(9);
		table.setBorderWidth(1);
		table.setBorderColor(new Color(0, 0, 0));
		table.setPadding(1);
		table.setSpacing(0);
		table.setWidth(100);
		//表头说明
		Cell cell = createCell("退货出库",fontChinese_14);
		cell.setHeader(true);
		cell.setColspan(9);
		table.addCell(cell);
		//cell.setRowspan(2);跨行
		//cell.setColspan(2);跨列
		//表头
		String[] tableHeader = new String[]{ "退货单号", "品项数", "仓库", "邮轮", "物料","应退金额", "实退金额", "提交时间", "提交人" };
		List<Cell> tableHeaderCellList = new ArrayList<Cell>();
		for (int i = 0; i < tableHeader.length; i++) {
			cell = createCell(tableHeader[i],fontChinese_14);
			tableHeaderCellList.add(cell);
		}
		for (int i = 0; i < tableHeader.length; i++) {
			table.addCell(tableHeaderCellList.get(i));
		}
		// 添加此代码后超出每页都会显示表头
		table.endHeaders();
		//System.out.println("=======listpk======"+roList.size());
		//SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
		//表格
		if(roList!=null){
			int listSize=roList.size();
			
			for (int i = 0; i < listSize; i++) {
				String strv = String.valueOf(roList.get(i).getShouldReceive());
				if (strv == null || strv == "" || strv.equals("")){
					strv = " ";
				} else{
					strv = String.valueOf(roList.get(i).getShouldReceive());
				}
				
				//String str = (listpr.get(i).getStatus()==1)?"已提交":"未提交";
				Cell cell1 = createCell(roList.get(i).getReturnNumber(),fontChinese_14);
				Cell cell6 = createCell(roList.get(i).getNumber().toString(),fontChinese_14);
				Cell cell4 = createCell(roList.get(i).getWarehouseName(),fontChinese_14);
				Cell cell5 = createCell(roList.get(i).getCruiseName(),fontChinese_14);
				Cell cell7 = createCell(roList.get(i).getMaterialMaterial().toString(),fontChinese_14);
				Cell cell2 = createCell(strv,fontChinese_14);
				Cell cell3 = createCell(strv,fontChinese_14);
				Cell cell8 = createCell(sdf.format(roList.get(i).getCommitTime()).toString(),fontChinese_14);
				Cell cell9 = createCell(roList.get(i).getSubmitterName(),fontChinese_14);
				table.addCell(cell1);
				table.addCell(cell6);
				table.addCell(cell4);
				table.addCell(cell5);
				table.addCell(cell7);
				table.addCell(cell2);
				table.addCell(cell3);
				table.addCell(cell8);
				table.addCell(cell9);
			}
		}
			
		
		return table;
	}
	
	/**
	 * 生成退货出库PDF单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static File ReturnOrderPDF(List<ReturnOrder> roList){

		try {
			bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		}catch (DocumentException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		fontChinese_14 = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
		fontChinese_16 = new com.lowagie.text.Font(bfChinese, 16, com.lowagie.text.Font.NORMAL);
		
		// Rectangle pageSize = new Rectangle(270, 300);//设置文档宽高
		Document document = new Document(PageSize.A4,10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
		//System.out.println("======================"+document.getPageSize().getWidth());
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
		String date = sdf2.format(new Date());
		File pdfFile = new File(FileUtil.TEMP_PATH +"退货出库_"+date+".pdf");
		try {
			PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath()));
		} catch (FileNotFoundException | DocumentException e1) {
			e1.printStackTrace();
		}
		
		document.open();

		try {
			Paragraph title = new Paragraph("退货出库", fontChinese_16);
			title.setAlignment(1);// 居中对齐
			document.add(title);
			document.add(buildReturnOrderTable(roList));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("打印时间："+sdf.format(new Date()), fontChinese_14));
			document.add(new Paragraph(" ", fontChinese_14));
			document.add(new Paragraph("负责人签名：", fontChinese_14));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		document.close();
		return pdfFile;
	}
	
}
